<?php
/**
 * View  LaFabbrica.org
 * 
 * @author     luigi.pastore (gigi@la-fabbrica.org)
 * @created    17-mag-2011
 * @package    LaFabbrica
 * @copyright  Copyright (c) 2011 Luigi Pastore
 */
?>
<script type="text/javascript">
    //<![CDATA[
     
    $(document).ready(function() {
	// Datepicker
	$( "#live_date_y" ).datepicker({
	    // Riempie i campi della data...
	    onSelect: function(dateText, inst) {
		var theDate = new Date(Date.parse($(this).datepicker('getDate')));
		var day = $.datepicker.formatDate('dd', theDate);
		var month = $.datepicker.formatDate('mm', theDate);
		var year = $.datepicker.formatDate('yy', theDate);
		$('#live_date_d').val(day);
		$('#live_date_m').val(month);
		$('#live_date_y').val(year);
	    },
	    showOn: "button",
	    showAnim: 'blind',
	    buttonImage: "/images/admin/calendar.png",
	    buttonImageOnly: true,
            defaultDate: '<?php echo $this->data['live_date_m'] ? $this->data['live_date_m'] : date( 'm' ) ?>/<?php echo $this->data['live_date_d'] ? $this->data['live_date_d'] : date( 'd' ) ?>/<?php echo $this->data['live_date_y'] ? $this->data['live_date_y'] : date( 'Y' ) ?>'
	});
        

	// a custom method for validating the date range
	$.validator.addMethod("validDate", function(value, element, classname) {
	    if($("#live_date_d").val() == '' && $("#live_date_m").val() == '' && $("#live_date_y").val() == '')
		return false;
	
	    try{$.datepicker.parseDate('ddmmyy', $("#live_date_d").val()+$("#live_date_m").val()+$("#live_date_y").val() );return true;}
	    catch(e){ console.log(e); return false;}

	}, "<?php echo ERR_DATE ?>");             
        
//
//        $("#live_status_id").rules("add", {
//            required: true,
//            messages: {
//                required: "<?php echo ERR_EMPTY ?>",
//                range: "<?php echo sprintf( ERR_FORMAT, 'Status' ) ?>"                
//            }
//        });
//        

        $(".radio").rules("add", {
            required: true,
            messages: {
                required: "<?php echo sprintf( ERR_EMPTY_SELECT, 'Stato' ) ?>"
            }
        });

        $("#live_price_1").rules("add", {
            number: true,
            messages: {
                number: "<?php echo ERR_INTEGER ?>"
            }
        });
        
        $("#live_price_2").rules("add", {
            number: true,
            messages: {
                number: "<?php echo ERR_INTEGER ?>"
            }
        });

        $("#live_stagetime_h").rules("add", {
            number: true,
            range: [0, 24],
            messages: {
                range: "<?php echo sprintf( ERR_FORMAT, 'Ora d\'inizio' ) ?>"
            }
        });
        
        $("#live_stagetime_m").rules("add", {
            number: true,
            range: [0, 59],
            messages: {
                range: "<?php echo sprintf( ERR_FORMAT, 'Ora d\'inizio' ) ?>"
            }
        });

        $("#live_loadin_h").rules("add", {
            number: true,
            range: [0, 24],
            messages: {
                range: "<?php echo sprintf( ERR_FORMAT, 'Ora Load-in' ) ?>"
            }
        });
        
        $("#live_loadin_m").rules("add", {
            number: true,
            range: [0, 59],
            messages: {
                range: "<?php echo sprintf( ERR_FORMAT, 'Ora Load-in' ) ?>"
            }
        });

        $("#live_soundcheck_h").rules("add", {
            number: true,
            range: [0, 24],
            messages: {
                range: "<?php echo sprintf( ERR_FORMAT, 'Ora Soundcheck' ) ?>"
            }
        });
        
        $("#live_soundcheck_m").rules("add", {
            number: true,
            range: [0, 59],
            messages: {
                range: "<?php echo sprintf( ERR_FORMAT, 'Ora Soundcheck' ) ?>"
            }
        });

        $("#live_doorsopen_h").rules("add", {
            number: true,
            range: [0, 24],
            messages: {
                range: "<?php echo sprintf( ERR_FORMAT, 'Ora Apertura Porte' ) ?>"
            }
        });
        
        $("#live_doorsopen_m").rules("add", {
            number: true,
            range: [0, 59],
            messages: {
                range: "<?php echo sprintf( ERR_FORMAT, 'Ora Apertura Porte' ) ?>"
            }
        });
        
        validator.groups = {live_date_d: "dateValid", live_date_m: "dateValid", live_date_y: "dateValid",
                            live_price_1: "live_price", live_price_2: "live_price",
                            live_stagetime_h: "live_stagetime", live_stagetime_m: "live_stagetime",
                            live_doorsopen_h: "live_doorsopen", live_doorsopen_m: "live_doorsopen"}


    });
	

    //]]>
</script>
<div id="content">
    <div id="summary" class="live">
	<div class="head live">
	    <h2>Live:</h2>
	</div>
	<div class="body">
	    <table cellspacing="0" class="table">
		<tbody>
		    <tr>
			<th>Artista:</th>
			<td>
			    <strong>
				<?php
				foreach( $this->artists['main'] as $artist ) :
				    $artists_list .= $artist['artist_name'] . ', ';
				endforeach;
				?>
				<?php echo substr( $artists_list, 0, -2 ); ?>
			    </strong>
			</td>
		    </tr>
		    <?php if( count( $this->artists['openingact'] ) ): ?>
    		    <tr>
    			<th>Open-act:</th>
    			<td>
    			    <strong>
				    <?php
				    $artists_list = null;
				    foreach( $this->artists['openingact'] as $artist ) :
					$artists_list .= $artist['artist_name'] . ', ';
				    endforeach;
				    ?>
				    <?php echo substr( $artists_list, 0, -2 ); ?>				
    			    </strong>
    			</td>
    		    </tr>				
		    <?php endif; ?>
		    <tr>
			<th>Location:</th>
			<td><strong><?php echo $this->location['location_name'] ?>, <?php echo $this->location['location_city'] ?> (<?php echo $this->province[$this->location['location_province_id']]['province_short_name'] ?>)</strong></td>
		    </tr>
		</tbody>
	    </table>
	</div>	
    </div>
    <form>
	<ul>
	    <li class="paging-context ">
		<table class="pgStyle1 circle2" cellspacing="0">
		    <tr>
			<td class="c">
			    <var>1</var>
			</td>
			<td class="t">
			    <b id="pagecircle1"><a href="/admin/live/artisti/id/<?php echo $this->live_id ?>">Artisti</a></b>
			</td>
			<td class="c">
			    <var>2</var>
			</td>
			<td class="t">
			    <b id="pagecircle2"><a href="/admin/live/location/id/<?php echo $this->live_id ?>">Location</a></b>
			</td>
			<td class="c selected">
			    <var>3</var>
			</td>
			<td class="t selected">
			    <b id="pagecircle2">Dettagli Live</b>
			</td>
			<td class="c">
			    <var>3</var>
			</td>
			<td class="t">
			    <b id="pagecircle2">Conferma</b>
			</td>			
		    </tr>
		</table>
	    </li>
	</ul>
    </form>
    <div class="help">
	<h2>Dettagli Live:</h2>
	<br/>
	<div>Inserisci i dettagli del concerto</div>
    </div>

    <form id="form-live" class="fab" method="post" action="/admin/live/info/id/<?php echo $this->live_id ?>">	    
	<ul>
	    <li id="errorLi" style="<?php echo $this->errorMsg ? '' : 'display:none' ?>">
		<h3 id="errorMsgLbl">Si &egrave; verificato un problema durante l'invio del modulo.</h3>
		<p id="errorMsg">
		Di seguito trovi evidenziati gli errori riscontrati.
		</p>
	    </li>
   
	    <li>
		<label class="desc">Stato Live</label>
		<div>
		    <?php 
		    foreach( $this->live_status AS $live_status ):
			?>
			<span class="input">
			    <input id="live_status<?php echo $live_status['live_status_id'] ?>" name="live_status_id" class="field radio" type="radio" value="<?php echo $live_status['live_status_id'] ?>" <?php echo ( $this->data['live_status_id'] == $live_status['live_status_id'] ) ? 'checked="checked"' : '' ?> />
			    <label class="choice" for="live_status<?php echo $live_status['live_status_id'] ?>"><?php echo $live_status['live_status_name'] ?></label>
			</span>			
			<?php
		    endforeach;
		    ?>
		</div>
		<p id="instruct" class="instruct">
		    <small>
		    <?php
		    foreach( $this->live_status AS $live_status ):
			?>
			<strong><?php echo $live_status['live_status_name'] ?>:</strong> <?php echo $live_status['live_status_desc']  ?><br />
			<?php
		    endforeach;
		    ?>			
		    </small>
		</p>		
	    </li>
	<li>
	    <label class="desc">Visibile?</label>
	    <div>
		<span class="input">
                    <input id="live_ispublic1" name="live_ispublic" class="field radio" type="radio" value="1" <?php echo ( $this->data['live_ispublic'] == 1 ? 'checked="checked"' : '' ) ?> />
		    <label class="choice" for="live_ispublic1">S&iacute;</label>
                </span>

		<span class="input">
                    <input id="live_ispublic2" name="live_ispublic" class="field radio" type="radio" value="0" <?php echo ( $this->data['live_ispublic'] == 0 ? 'checked="checked"' : '' ) ?> />
		    <label class="choice" for="live_ispublic2">No</label>
                </span>
	    </div>
                <p class="instruct">
                    <small>
                        <strong>S&iacute;:</strong> Se impostato, ed il live è in stato <em>Confermato</em>, questo verr&agrave; visualizzato online.<br/>
                        <strong>No:</strong> Il live non verr&agrave; visualizzato, indipendentemente dal suo stato.<br/>
                    </small>
                </p>            
            </li>            
	    <li class="section">
		<h3>Data</h3>
	    </li>

	    <li class="<?php echo $this->errorMsg['live_date'] ? 'error' : '' ?>">
		<label class="desc <?php echo $this->errorMsg['live_date'] ? 'error' : '' ?>">Data del live<span class="req">*</span></label>
		<div class="float-left">
		    <span class="input">
			<input class="field text dateValid" name="live_date_d" id="live_date_d" size="2" type="text" maxlength="2" value="<?php echo $this->data['live_date_d'] ? $this->data['live_date_d'] : date( 'd' ) ?>" /> / 
			<label>GG</label>
		    </span>

		    <span class="input">
			<input class="field text dateValid" name="live_date_m" id="live_date_m" size="2" type="text" maxlength="2" value="<?php echo $this->data['live_date_m'] ? $this->data['live_date_m'] : date( 'm' ) ?>" /> / 
			<label>MM</label>
		    </span>

		    <span class="input">
			<input class="field text dateValid" name="live_date_y" id="live_date_y" size="4" type="text" maxlength="4" value="<?php echo $this->data['live_date_y'] ? $this->data['live_date_y'] : date( 'Y' ) ?>" />
			<label>AAAA</label>
		    </span>
		</div>
		<p class="error" style="<?php echo $this->errorMsg['live_date'] ? 'display:block' : '' ?>"><?php echo $this->errorMsg['live_date'] ?></p>
	    </li>
            <li class="section">
		<h3>Orari</h3>
	    </li>

	    <li class="<?php echo $this->errorMsg['live_stagetime'] ? 'error' : '' ?>">
		<label class="desc <?php echo $this->errorMsg['live_stagetime'] ? 'error' : '' ?>">Stage Time</label>
		<div class="float-left">
		    <span class="input">
			<input class="field text hour" size="2" name="live_stagetime_h" id="live_stagetime_h" type="text" maxlength="2" value="<?php echo $this->data['live_stagetime_h'] ? $this->data['live_stagetime_h'] : '22' ?>"/> : 
			<label for="live_stagetime_h">HH</label>
		    </span>

		    <span class="input">
			<input class="field text" size="2" name="live_stagetime_m" id="live_stagetime_m" type="text" maxlength="2" value="<?php echo $this->data['live_stagetime_m'] ? $this->data['live_stagetime_m'] : '00' ?>"/>
			<label for="live_stagetime_m">MM</label>
		    </span>
		    <p class="error" style="<?php echo $this->errorMsg['live_stagetime'] ? 'display:block' : '' ?>"><?php echo $this->errorMsg['live_stagetime'] ?></p>
		</div>
                <p class="instruct">
                    <small>Inserisci gli orari del live.<br/>
                        <strong>Loadin:</strong>L'orario in cui arrivare al locale.<br/>
                        <strong>Soundcheck:</strong>L'ora del soundcheck.<br/>
                        <strong>Stagetime:</strong>L'ora di inizio del live. Se l'orario viene lasciato vuoto verr&agrave; usato quello di default (22h00).<br/>
                        <strong>Doors:</strong>L'ora di apertura al pubblico della location.
                    </small>
                </p>
	    </li>
            
	    <li class="<?php echo $this->errorMsg['live_loadin'] ? 'error' : '' ?>">
		<label class="desc <?php echo $this->errorMsg['live_loadin'] ? 'error' : '' ?>">Load-in</label>
		<div class="float-left">
		    <span class="input">
			<input class="field text hour" size="2" name="live_loadin_h" id="live_loadin_h" type="text" maxlength="2" value="<?php echo $this->data['live_loadin_h'] ? $this->data['live_loadin_h'] : '22' ?>"/> : 
			<label for="live_loadin_h">HH</label>
		    </span>

		    <span class="input">
			<input class="field text" size="2" name="live_loadin_m" id="live_loadin_m" type="text" maxlength="2" value="<?php echo $this->data['live_loadin_m'] ? $this->data['live_loadin_m'] : '00' ?>"/>
			<label for="live_loadin_m">MM</label>
		    </span>
		    <p class="error" style="<?php echo $this->errorMsg['live_loadin'] ? 'display:block' : '' ?>"><?php echo $this->errorMsg['live_loadin'] ?></p>
		</div>
	    </li>
            
	    <li class="<?php echo $this->errorMsg['live_soundcheck'] ? 'error' : '' ?>">
		<label class="desc <?php echo $this->errorMsg['live_soundcheck'] ? 'error' : '' ?>">Soundcheck</label>
		<div class="float-left">
		    <span class="input">
			<input class="field text hour" size="2" name="live_soundcheck_h" id="live_soundcheck_h" type="text" maxlength="2" value="<?php echo $this->data['live_soundcheck_h'] ? $this->data['live_soundcheck_h'] : '22' ?>"/> : 
			<label for="live_soundcheck_h">HH</label>
		    </span>

		    <span class="input">
			<input class="field text" size="2" name="live_soundcheck_m" id="live_soundcheck_m" type="text" maxlength="2" value="<?php echo $this->data['live_soundcheck_m'] ? $this->data['live_soundcheck_m'] : '00' ?>"/>
			<label for="live_soundcheck_m">MM</label>
		    </span>
		    <p class="error" style="<?php echo $this->errorMsg['live_soundcheck'] ? 'display:block' : '' ?>"><?php echo $this->errorMsg['live_soundcheck'] ?></p>
		</div>
	    </li>

	    <li class="<?php echo $this->errorMsg['live_doorsopen'] ? 'error' : '' ?>">
		<label class="desc <?php echo $this->errorMsg['live_doorsopen'] ? 'error' : '' ?>">Apertura dei cancelli</label>
		<div class="float-left">
		    <span class="input">
			<input class="field text hour" size="2" name="live_doorsopen_h" id="live_doorsopen_h" type="text" maxlength="2" value="<?php echo $this->data['live_doorsopen_h'] ?>"/> : 
			<label for="live_doorsopen_h">HH</label>
		    </span>

		    <span class="input">
			<input class="field text" size="2" name="live_doorsopen_m" id="live_doorsopen_m" type="text" maxlength="2" value="<?php echo $this->data['live_doorsopen_m'] ?>"/>
			<label for="live_doorsopen_m">MM</label>
		    </span>
		    <p class="error" style="<?php echo $this->errorMsg['live_doorsopen'] ? 'display:block' : '' ?>"><?php echo $this->errorMsg['live_doorsopen'] ?></p>
		</div>
	    </li>
            
	    <li class="section">
		<h3>Altre Informazioni</h3>
	    </li>

	    <li class="<?php echo $this->errorMsg['live_price'] ? 'error' : '' ?>">
		<label class="desc">Ingresso</label>
		<div class="float-left">
		    <span class="symbol">
			&euro;
		    </span>

		    <span class="input">
			<input class="field text currency" name="live_price_1" id="live_price_1" type="text" size="10" value="<?php echo $this->data['live_price_1'] ?>"/> .
		    </span>

		    <span class="input">
			<input class="field text" size="2" name="live_price_2" id="live_price_2" type="text" maxlength="2" value="<?php echo $this->data['live_price_2'] ? $this->data['live_price_2'] : '00' ?>"/>
		    </span>
		    <p class="error" style="<?php echo $this->errorMsg['live_price'] ? 'display:block' : '' ?>"><?php echo $this->errorMsg['live_price'] ?></p>
		    <p class="instruct">
			<small>Inserisci il prezzo d'ingresso.</small>
		    </p>		
		</div>
	    </li>	    

	    <li class="<?php echo $this->errorMsg['live_notes'] ? 'error' : '' ?>">
		<label class="desc <?php echo $this->errorMsg['live_notes'] ? 'error' : '' ?>">Note</label>
		<div>
		    <span>
			<textarea id="live_notes" class="field textarea small" name="live_notes" rows="3" cols="100"><?php echo htmlentities( $this->data['live_notes'] ) ?></textarea>
		    </span>
		</div>
		<p class="error" style="<?php echo $this->errorMsg['live_notes'] ? 'display:block' : '' ?>"><?php echo $this->errorMsg['live_notes'] ?></p>
	    </li>	    
	</ul>
	<br style="clear: both" />
</div>
<input type="hidden" name="live_location_id" id="live_location_id" value="<?php echo $_SESSION['Live']['Info']['live_location_id'] ?>" />
<input type="hidden" name="conferma" id="conferma" value="conferma" />
<div id="formButtons">
    <button id="salva" name="salva" value="salva" class="button positive">
	<img src="/images/admin/tick.png" alt="" />Continua
    </button>
    <button id="annulla" name="annulla" value="annulla" class="button negative">
	<img src="/images/admin/cross.png" alt="" />Annulla
    </button>

</div>
</form>